<%
 '
 ' Copyright 2007 Liu, Xiaokang <4341322@gmail.com>
 ' Blog <http://www.ioio.name/>
 ' 
 ' This file is part of JOS(Judge Online System).
 ' You can see this project at <http://code.google.com/p/judgeonline/>
 ' 
 ' JOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 ' published by the Free Software Foundation; either revision 3 of the License, or (at your option) any later revision.
 ' 
 ' JOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 ' 
 ' You should have received a copy of the GNU General Public License along with JOS. if not, see
 ' <http://www.gnu.org/licenses/>.
 '
%>
<%Option Explicit%>
<%
	Dim PageTitle
  PageTitle="Problem Set"
%>
<!--#include file="Header.asp"-->
<!--#include file="Upload_5xsoft.asp"-->
<div id="Main">
<%
Dim ppath,pro_id,upload,filet,filename,commd,WshShell,succ,ProblemTmp
If IsLogin and IsAdmin Then
	set upload=new upload_5xsoft 
	set filet=upload.file("FileBin")
	if filet.fileSize>0 then 
		pro_id = upload.Form("pid") 
		if upload.Form("Submit")="Submit" and pro_id<>"" then
		
	ppath = ProblemPath & "P" & pro_id
	dim fs,fo
	set fs=Server.CreateObject("Scripting.FileSystemObject")
	If fs.FolderExists(ppath) Then
	set fo=fs.GetFolder(ppath)
	fo.Delete(True)	
	End If
	set fo=nothing
	set fs=nothing
	
	filename= ProblemTmpPath & "TEMPUPLOAD.zip" 
	filet.saveAs filename 
		
	commd= CompilerPath & "WinRAR\RAR x -o+ " & filename & " " &  ProblemPath & "P" & pro_id &"\"
	set WshShell = server.createobject("wscript.shell") 
	succ=WshShell.Run(commd,0,true)

	conn.Open connstr
	Set ProblemTmp = Server.CreateObject("ADODB.Recordset")
	ProblemTmp.Open  "Select * from Problems Where Pid="+pro_id,conn,1,3
	If problemtmp.recordcount=1 Then
	ProblemTmp("Pname")=upload.Form("Name")
	ProblemTmp.update
	End If
	ProblemTmp.Close
	Set ProblemTmp=Nothing
	conn.Close
	
		Sub   DeleteFile(FilePath)   
		Dim   fso   
		Set   fso   =   CreateObject("Scripting.FileSystemObject")   
		IF   fso.FileExists(FilePath)   Then   
		fso.DeleteFile(FilePath)   
		End   IF   
		Set   fso   =   Nothing   
		End   Sub
		
		DeleteFile(filename)
		set filet=nothing
		set upload=nothing
		set WshShell=nothing
		response.Write("update success")	
	    end if
	else
	%>
    <form action="#" method="post" enctype="multipart/form-data" name="form1">
<table width="400" border="0">
  <tr>
    <td class="FontBig">Problem Id</td>
    <td><%=Request.QueryString("Pid")%><input type="hidden" name="pid" value="<%=Request.QueryString("Pid")%>" /></td>
  </tr>
  <tr>
    <td class="FontBig">Problem Title</td>
    <td><input name="Name" id="asad" /></td>
  </tr>
  <tr>
    <td class="FontBig">Problem Zip File</td>
    <td><input type="file" name="FileBin" /></td>
  </tr>
  <tr>
    <td class="FontBig"></td>
    <td><input type="submit" value="Submit" name="Submit" />  		
    	<input id="Reset" type="reset" value="Canel" name="Reset" /></td>
  </tr>
</table>

         </form>

    <%
	end if
	
Else
	Response.Write "Permission Denied."
End If
%>
</div>
<!--#include file="Footer.asp"-->